import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/hj_page/mine_business/collec_history_buy/col_hist_buy_controller.dart';
import 'package:tiktokadult/tools_base/indicator/custom_tab_indicator.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

enum PageType {
  collect('我的收藏'),
  buy('我的购买'),
  history('历史记录'),
  like('我的喜欢');

  final String title;

  const PageType(this.title);
}

/// 收藏 历史 购买列表 喜欢
class ColHisBuyPage extends StatelessWidget {
  final PageType type;

  const ColHisBuyPage(this.type, {super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<BaseColHisBuyMainController>(
      init: instanceController(type),
      builder: (logic) {
        return Scaffold(
          appBar: AppBar(
            title: Text(type.title),
            actions: [
              if (type == PageType.collect || type == PageType.history)
                GestureDetector(
                  onTap: () => logic.onDeteleAction(),
                  child: Padding(
                    padding: EdgeInsets.only(right: 16),
                    child: Text(
                      logic.isEdit ? '完成' : '编辑',
                      style: textStyle(14, Color(0xff666666), FontWeight.w400),
                    ),
                  ),
                ),
            ],
          ),
          body: Column(
            children: [
              Container(
                color: Theme.of(context).appBarTheme.backgroundColor,
                child: TabBar(
                  labelPadding: EdgeInsets.zero,
                  padding: EdgeInsets.only(left: 8.w),
                  tabAlignment: TabAlignment.start,
                  indicator: CustomIndicator(
                    width: 16,
                    height: 3,
                    useGradient: true,
                    gradientColors: [Color(0x00E1351F), Color(0xffE1351F)],
                  ),
                  indicatorWeight: 1,
                  unselectedLabelStyle: TextStyle(color: Color(0xffcccccc), fontSize: 14, height: 1),
                  labelStyle: TextStyle(
                    color: Colors.white,
                    fontSize: 14,
                    height: 1,
                    fontWeight: FontWeight.w500,
                  ),
                  isScrollable: true,
                  tabs: logic.sorts
                      .map(
                        (e) => Padding(
                          padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
                          child: Text(e),
                        ),
                      )
                      .toList(),
                  controller: logic.controller,
                ),
              ),
              Expanded(
                child: TabBarView(
                  children: logic.instanceChildren(),
                  controller: logic.controller,
                ),
              )
            ],
          ),
        );
      },
    );
  }
}
